# 员工管理接口对象层
import requests


class EmpManageApi(object):
    def add_emp( self,req_header, req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                             headers=req_header, json=req_body)
        return resp

    def query_emp(self , emp_id,req_header):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_header)
        return resp

    def modify_emp(self, emp_id,req_header, req_body):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_header, json=req_body)
        return resp

    def del_emp(self,emp_id, req_header):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                               headers=req_header)
        return resp
if __name__ == '__main__':
   emp= EmpManageApi()

   resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
                          json={"mobile": "13800000002", "password": "123456"})
   print("登录成功",resp.json())
   token = resp.json().get("data")
   req_header={"Content-Type": "application/json","Authorization": token}
   #添加员工
   req_body = {"username": "张三疯007", "mobile": "18989089012","workNumber": "9527"}
   resp=emp.add_emp(req_header,req_body)
   print("添加成功:",resp.json())

   emp_id="1545373800093200384"            #查询员工
   resp= emp.query_emp(emp_id,req_header)
   print("查询",resp.json())


   emp_mod_req_body= {"username": "至宗宝99"}     #修改
   resp=emp.modify_emp(emp_id,req_header, emp_mod_req_body)
   print("修改",resp.json())

   emp.del_emp(emp_id,req_header)          #删除
   print("删除",resp.json())